# smtplib 用于邮件的发信动作
import smtplib
from email.mime.text import MIMEText
# email 用于构建邮件内容
from email.header import Header
import socket
import getpass
import pandas as pd
import datetime


def sendEmail(title, body, fromAddress='yehb@qq.com', toAddress='amstelveen@dingtalk.com'):
    # 用于构建邮件头

    # 发信方的信息：发信邮箱，QQ 邮箱授权码
    # yehb@qq.com
    from_addr = fromAddress
    password = 'pjotakumnnhobjja'

    # 收信方邮箱
    # amstelveen@dingtalk.com
    to_addr = toAddress

    # 发信服务器
    smtp_server = 'smtp.qq.com'

    # 邮箱正文内容，第一个参数为内容，第二个参数为格式(plain 为纯文本)，第三个参数为编码
    msg = MIMEText(body, 'plain', 'utf-8')

    # 邮件头信息
    msg['From'] = Header(from_addr)
    msg['To'] = Header(to_addr)
    msg['Subject'] = Header(title)

    # 开启发信服务，这里使用的是加密传输
    server = smtplib.SMTP_SSL(host=smtp_server)
    server.connect(smtp_server, 465)
    # 登录发信邮箱
    server.login(from_addr, password)
    # 发送邮件
    server.sendmail(from_addr, to_addr, msg.as_string())
    # 关闭服务器
    server.quit()
    # print("发送了一封邮件")


if __name__ == '__main__':
    sendEmail('昨天邮件无法发送', '昨天邮件无法发送，看看是否是接口问题')
